package com.atguigu.srb.core.controller.api;


import com.atguigu.srb.common.result.R;
import com.atguigu.srb.core.entity.Dict;
import com.atguigu.srb.core.service.DictService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 数据字典 前端控制器
 * </p>
 *
 * @author Atguigu
 * @since 2023-06-30
 */
@RestController
@RequestMapping("/api/core/dict")
@Api(tags = "会员数据字典查询模块")
public class ApiDictController {
    @Resource
    DictService dictService;
    //获取用户字典的集合
    @ApiOperation("查询字典信息")
    @GetMapping("borrower")
    public R getDictInfo(){
        Map<String,Object> map =  dictService.getDictList();
        return R.ok().data(map);
    }
    //根据父节点的dictCode获取字典集合
    @ApiOperation("根据父节点的dictCode获取字典集合")
    @GetMapping("/listDict/{dictCode}")
    public R listDictsBydictCode(@PathVariable("dictCode")String dictCode){
        List<Dict> dicts = dictService.listByDictCode(dictCode);
        return R.ok().data("items",dicts);
    }
}

